import { User } from "../user/user.entity";
import { Logs } from "../logs/logs.entity";
import { Roles } from "../roles/roles.entity";
import { Menus } from "../menus/menu.entity";
import { Profile } from "../user/profile.entity";

/**
 * 根据请求路径前缀返回对应的实体类型或标识。
 * @param path 请求路径（如 "/users", "/logs"）
 * @returns 对应的实体类（User/Logs/Roles/Menus）或字符串 "Auth"（用于鉴权相关路径）
 */
export const getEntitiesByPath = (path: string) => {
  // 路径到实体的映射表：用于根据接口前缀快速定位实体
  const map = {
    "/users": User,
    "/logs": Logs,
    "/roles": Roles,
    "/menus": Menus,
    "/profile": Profile,
    "/auth": "Auth",
    "/article-list": "ArticleList",
    "/article-create": "ArticleCreate",
    "/cart": "Cart",
    "/product-list": "ProductList",
    "/my-order": "MyOrder",
  };

  // 遍历映射表的键，按前缀判断：若请求路径以某键开头，则返回其对应的实体/标识
  for (let i = 0; i < Object.keys(map).length; i++) {
    const key = Object.keys(map)[i];
    if (path.startsWith(key)) {
      return map[key];
    }
  }
};
